package Day11;

/**
 * @author HYHwtx
 * @version 1.0
 * @date 2022/2/17 10:43
 */
//2.13	定义一个int[] a =｛4，2，0，-1，-8，23，9｝
// 求数组元素的最大值、最小值、平均数、总和、数组的复制、反转
public class Test13 {
    public static void main(String[] args) {
        int a [] = {4,2,0,-1,-8,23,9};
        int max = a[0];//最大值
        int min = a[0];//最小值
        int arave = 0;//平均值
        int sum = 0;//总和
        for (int i = 0; i < a.length; i++) {
            if (a[i]>max){
                max = a[i];
            }
        }
        System.out.println("最大值为："+max);
        for (int i = 0; i < a.length; i++) {
            if (a[i]<min){
                min = a[i];
            }
        }
        System.out.println("最小值为："+min);
        for (int i = 0; i < a.length; i++) {
            sum = sum+a[i];
        }
        System.out.println("总和为："+sum);
        arave = (sum/a.length);
        System.out.println("平均值为："+arave);
        //数组的复制
        int [] a2 = new int[a.length];//新建一个数组
        for (int i = 0; i < a2.length; i++) {
            a2[i] = a[i];
        }
        System.out.println("复制后的结果为：");
        for (int i = 0; i < a2.length; i++) {
            System.out.print(a2[i]+" ");
        }
        //数组的反转
        int temp = 0;
        int len = a.length;
        for (int i = 0; i < len / 2; i++) {
            temp = a[len-1-i];
            a[len-1-i] =a[i];
            a[i] = temp;
        }
        System.out.println("反转结果为：");
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]+" ");
        }
    }

}
